this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.Ui=this.BX.Landing.Ui||{};(function(e,t,n,r,a,i,o,l){"use strict";var c,s,u;function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){babelHelpers.defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var d=function(e){babelHelpers.inherits(t,e);function t(){var e;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};babelHelpers.classCallCheck(this,t);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this));e.setEventNamespace("BX.Landing.UI.Field.Color.Opacity");e.subscribeFromOptions(i.fetchEventsFromOptions(n));e.options=p({},n);e.cache=new r.Cache.MemoryCache;e.onPickerDragStart=e.onPickerDragStart.bind(babelHelpers.assertThisInitialized(e));e.onPickerDragMove=e.onPickerDragMove.bind(babelHelpers.assertThisInitialized(e));e.onPickerDragEnd=e.onPickerDragEnd.bind(babelHelpers.assertThisInitialized(e));e.draggable=new window.top.BX.UI.DragAndDrop.Draggable({container:e.getLayout(),draggable:".landing-ui-field-color-opacity-picker",type:a.Draggable.HEADLESS});e.draggable.subscribe("start",e.onPickerDragStart);e.draggable.subscribe("move",e.onPickerDragMove);e.draggable.subscribe("end",e.onPickerDragEnd);return e}babelHelpers.createClass(t,[{key:"getLayout",value:function e(){var t=this;return this.cache.remember("layout",(function(){return r.Tag.render(c||(c=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-field-color-opacity">\n\t\t\t\t\t',"\n\t\t\t\t\t","\n\t\t\t\t</div>\n\t\t\t"])),t.getPicker(),t.getColorLayout())}))}},{key:"getColorLayout",value:function e(){return this.cache.remember("colorLayout",(function(){return r.Tag.render(s||(s=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-field-color-opacity-color"></div>\n\t\t\t'])))}))}},{key:"getColorLayoutWidth",value:function e(){var t=this;return this.cache.remember("colorLayoutWidth",(function(){return t.getColorLayout().getBoundingClientRect().width-6}))}},{key:"getPicker",value:function e(){return this.cache.remember("picker",(function(){return r.Tag.render(u||(u=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div \n\t\t\t\t\tclass="landing-ui-field-color-opacity-picker"\n\t\t\t\t\ttitle="','"\n\t\t\t\t></div>\n\t\t\t'])),o.Loc.getMessage("LANDING_COLORPICKER_FIELD_CHANGE_COLOR_OPACITY"))}))}},{key:"getValue",value:function e(){var t=r.Text.toNumber(r.Dom.style(this.getPicker(),"left"));var n=r.Text.toNumber(this.getLayout().getBoundingClientRect().width);return 1-(t/n).toFixed(1)}},{key:"setValue",value:function e(t){var n=t.parsedColor,a=t.skipOpacity,i=a===void 0?false:a;var o="rgba(".concat([n.slice(0,3),100].join(", "),")");var l="rgba(".concat([n.slice(0,3),0].join(", "),")");r.Dom.style(this.getColorLayout(),{background:"linear-gradient(to right, ".concat(o," 0%, ").concat(l," 100%)")});if(!i){var c=n[3]||0;var s=100-c*100;r.Dom.style(this.getPicker(),{left:"calc(".concat(s,"% - ").concat(s===100?"6px":"0px",")")})}}},{key:"onPickerDragStart",value:function e(){this.cache.set("pickerStartPos",{left:r.Text.toNumber(r.Dom.style(this.getPicker(),"left"))});var t=l.PageObject.getRootWindow().document.querySelector(".landing-ui-view-wrapper");r.Dom.style(t,"pointer-events","none")}},{key:"onPickerDragMove",value:function e(t){var n=t.getData(),a=n.offsetX;var i=this.cache.get("pickerStartPos"),o=i.left;var l=Math.min(Math.max(o+a,0),this.getColorLayoutWidth());r.Dom.style(this.getPicker(),{left:"".concat(l,"px")});this.emit("onChange")}},{key:"onPickerDragEnd",value:function e(){var t=l.PageObject.getRootWindow().document.querySelector(".landing-ui-view-wrapper");r.Dom.style(t,"pointer-events",null)}}]);return t}(n.EventEmitter);var b,f,h,y;var v=function(e){babelHelpers.inherits(t,e);function t(e){var n;babelHelpers.classCallCheck(this,t);n=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));n.setEventNamespace("BX.Landing.UI.Field.ColorPickerField");n.setLayoutClass("landing-ui-field-colorpicker");r.Dom.append(n.getColorLayout(),n.input);n.setValue(n.options.value);return n}babelHelpers.createClass(t,[{key:"getUid",value:function e(){return this.cache.remember("uid",(function(){t.id+=1;return"".concat(r.Text.getRandom()).concat(t.id)}))}},{key:"getColorLabelInner",value:function e(){return this.cache.remember("colorLabelInner",(function(){return r.Tag.render(b||(b=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span class="landing-ui-field-colorpicker-label-inner"></span>\n\t\t\t'])))}))}},{key:"getColorLabel",value:function e(){var t=this;return this.cache.remember("colorLabel",(function(){return r.Tag.render(f||(f=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<label \n\t\t\t\t\tclass="landing-ui-field-colorpicker-label"\n\t\t\t\t\tfor="','"\n\t\t\t\t\ttitle="','"\n\t\t\t\t>\n\t\t\t\t\t',"\n\t\t\t\t</label>\n\t\t\t"])),t.getUid(),o.Loc.getMessage("LANDING_COLORPICKER_FIELD_CHANGE_COLOR_TITLE"),t.getColorLabelInner())}))}},{key:"getColorInput",value:function e(){var t=this;return this.cache.remember("colorInput",(function(){return r.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<input \n\t\t\t\t\ttype="color" \n\t\t\t\t\tclass="landing-ui-field-colorpicker-input"\n\t\t\t\t\tid="','"\n\t\t\t\t\toninput="','"\n\t\t\t\t\tonchange="','"\n\t\t\t\t>\n\t\t\t'])),t.getUid(),t.onInputChange.bind(t),t.onInputChange.bind(t))}))}},{key:"onInputChange",value:function e(){this.setValue(this.getColorInput().value,false,true)}},{key:"getColorLayout",value:function e(){var t=this;return this.cache.remember("colorLayout",(function(){return r.Tag.render(y||(y=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-field-colorpicker-layout">\n\t\t\t\t\t',"\n\t\t\t\t\t","\n\t\t\t\t\t","\n\t\t\t\t</div>\n\t\t\t"])),t.getColorLabel(),t.getColorInput(),t.getOpacityField().getLayout())}))}},{key:"getOpacityField",value:function e(){var n=this;return this.cache.remember("opacityField",(function(){return new d({onChange:function e(){var a=t.parseHex(n.getColorInput().value);a[3]=n.getOpacityField().getValue();r.Dom.style(n.getColorLabelInner(),{backgroundColor:t.toRgba.apply(t,babelHelpers.toConsumableArray(a))});n.emit("onChange")}})}))}},{key:"setValue",value:function e(n){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var i=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var o=t.parseHex(n);var l=t.toHex.apply(t,babelHelpers.toConsumableArray(o));if(n.length===7){o[3]=this.getOpacityField().getValue()}r.Dom.style(this.getColorLabelInner(),{backgroundColor:t.toRgba(o)});this.getColorInput().value=l.slice(0,7);this.getOpacityField().setValue({parsedColor:o,skipOpacity:i});if(!a){this.emit("onChange")}}},{key:"getValue",value:function e(){var n=t.parseHex(this.getColorInput().value);n[3]=this.getOpacityField().getValue();return t.toHex.apply(t,babelHelpers.toConsumableArray(n))}}],[{key:"prepareHex",value:function e(t){if(r.Type.isStringFilled(t)){var n=t.replace("#","");if(n.length===3){return"#".concat(n.split("").reduce((function(e,t){return"".concat(e).concat(t).concat(t)}),""))}}return t}},{key:"parseHex",value:function e(n){n=t.fillHex(n);var r=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(n);if(!r){r=[0,0,0,1]}else{r=[parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16),parseInt(100*(parseInt(r[4]||"ff",16)/255))/100]}return r}},{key:"fillHex",value:function e(t,n){if(t.length===4||n&&t.length===5){t=t.replace(/([a-f0-9])/gi,"$1$1")}if(n&&t.length===7){t+="ff"}return t}},{key:"toHex",value:function e(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++){n[r]=arguments[r]}n[3]=typeof n[3]==="undefined"?1:n[3];n[3]=parseInt(255*n[3]);return"#".concat(n.map((function(e){e=e.toString(16);return e.length===1?"0".concat(e):e})).join(""))}},{key:"hexToRgba",value:function e(t){return"rgba(".concat(this.parseHex(t).join(", "),")")}},{key:"toRgba",value:function e(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++){n[r]=arguments[r]}return"rgba(".concat(n.join(", "),")")}}]);return t}(t.BaseField);babelHelpers.defineProperty(v,"id",0);e.ColorPickerField=v})(this.BX.Landing.Ui.Field=this.BX.Landing.Ui.Field||{},BX.Landing.UI.Field,BX.Event,BX,BX.UI.DragAndDrop,BX.Landing.UI.Component,BX.Landing,BX.Landing);
//# sourceMappingURL=colorpickerfield.bundle.map.js